package ro.gateway.aida.db;

import ro.gateway.aida.srv.ICFService;
import ro.gateway.aida.srv.IIDGenerator;



/**
 * <p>Title: Romanian AIDA</p>
 * <p>Description: </p>
 * <p>Copyright: Copyright (comparator) 2003</p>
 * <p>Company: ro-gateway</p>
 * @author Mihai Popoaei, mihai_popoaei@yahoo.com, smike@intellisource.ro
 * @version 1.0-* @version $Id: DBPersistenceToken.java,v 1.1 2004/10/24 23:37:09 mihaipostelnicu Exp $
 */
public class DBPersistenceToken extends PersistenceToken
{
      private ICFService cfService;
      private IIDGenerator idgenerators;
      private String pool_name;

      public DBPersistenceToken(
            ICFService cfService,
            IIDGenerator idgenerator,
            String pool_name )
      {
            this.cfService = cfService;
            this.pool_name = pool_name;
            this.idgenerators = idgenerator;

            this.properties.put( "cfservice", cfService );
            this.properties.put( "pool_name", pool_name );
            this.properties.put( "idgenerators", idgenerator );
      }

      public void removeProperty( String name )
      {
            super.removeProperty( name );
            if ( "cfservice".equals( name ) )
            {
                  cfService = null;
            }
            else if ( "pool_name".equals( name ) )
            {
                  pool_name = null;
            }
            else if ( "idgenerators".equals( name ) )
            {
                  idgenerators = null;
            }
      }

      public void setProperty( String name, Object obj )
      {
            if ( name == null || obj == null ) return;

            if ( "cfservice".equals( name ) )
            {
                  if ( obj instanceof ICFService )
                  {
                        this.cfService = ( ICFService ) obj;
                  }
                  else
                  {
                        throw new RuntimeException( "invalid parameters (icfservice expected)" );
                  }
            }
            else if ( "pool_name".equals( name ) )
            {
                  if ( obj instanceof String )
                  {
                        this.pool_name = ( String ) obj;
                  }
                  else
                  {
                        throw new RuntimeException( "invalid parameters (String expected)" );
                  }
            }
            else if ( "idgenerators".equals( name ) )
            {
                  if ( obj instanceof IIDGenerator )
                  {
                        this.idgenerators = ( IIDGenerator ) obj;
                  }
                  else
                  {
                        throw new RuntimeException( "invalid parameters (IIDGenerator expected)" );
                  }
            }
            super.setProperty( name, obj );
      }

      public ICFService getCFService()
      {
            return cfService;
      }

      public String getPool_name()
      {
            return pool_name;
      }

      public IIDGenerator getIdgenerators() {
            return idgenerators;
      }
}
